//
// Created by kevin on 2024/11/26.
//


#include<string>
#include<iostream>
#include <algorithm>
#include <cctype>
#include "lte_para.h"

std::map<std::string, int> BandInfo;
std::map<std::string, int> BandWidth;

unsigned int init_para(std::map<std::string, int> & para, unsigned int beginidx, const std::string input[], int len){

    int l = sizeof(input) / sizeof(input[0]);
    for(int i = beginidx; i < len; i++){
        para.insert(std::make_pair(input[i], i));
    }

    return len;
}

void init_para(std::map<std::string, int> & para){

    int len = sizeof(validBandwidths) / sizeof(validBandwidths[0]);
    for(int i = 0; i < len; i++){
        para.insert(std::make_pair(validBandwidths[i], i));
    }

    int length = sizeof(validBandwidthsCustom) / sizeof(validBandwidthsCustom[0]);
    int loop = len + length;
    for(int i = len, idx = 0; i < loop; i++){

        para.insert(std::make_pair(validBandwidthsCustom[idx++], i));
    }
}

void tolower(std::string &str) {
    std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) {
        return std::tolower(c);
    });
}

void toupper(std::string& str) {
    for (char& c : str) {
        c = std::toupper(static_cast<unsigned char>(c)); // 使用std::toupper转换每个字符为大写
    }
}
/*
bool validateTestModelNo(std::string mod) {
    int length = sizeof(lteSupportedTestModels) / sizeof(lteSupportedTestModels[0]);

    int res = 0;
    for (int i = 0; i < length; i++) {
        tolower(mod);
        res = strcmp(mod.c_str(), lteSupportedTestModels[i].c_str());
        if (!res) {
            std::cout << "get mod:"<<mod << std::endl;
            break;
        }
    }
    if (!res) {
        return true;
    }
    else {
        return false;
    }
}
*/

bool validateTestModelNo(const std::string mod) {
    int length = sizeof(lteSupportedTestModels) / sizeof(lteSupportedTestModels[0]);

    int res = 0;
    for (int i = 0; i < length; i++) {
        res = lteSupportedTestModels[i].compare(mod);
        if (!res) {
            std::cout << "get mod:" << mod << std::endl;
            break;
        }
    }
    if (!res) {
        return true;
    }
    else {
        return false;
    }
}

bool validateBandwidth(const std::string tmNo, const std::string bw) {

    int length = sizeof(validBandwidths) / sizeof(validBandwidths[0]);
    bool res0, res1;

    for (int i = 0; i < length; i++) {
        int res = validBandwidths[i].compare(bw);
        if (res == 0) {
            res0 = true;
        }

        int rr = validBandwidthsCustom[i].compare(bw);
        if (rr == 0) {
            res1 = true;
        }
    }

    if (res0 != 0 && res1 != 0) {
        std::cout << "lte:error,The function call resulted in an error: The input parameter BW should be one of {''1.4MHz'', ''3MHz'', ''5MHz'', ''10MHz'', ''15MHz'', ''20MHz'', ''9RB'', ''11RB'', ''27RB'', ''45RB'', ''64RB'', ''91RB''}" << std::endl;
    }

    const std::string tmp = "1.1";
    int rr = tmNo.compare(tmp);
    if (rr != 0) {
        std::cout <<"lte:error, The function call resulted in an error : The input parameter BW can only be one of{''9RB'', ''11RB'', ''27RB'', ''45RB'', ''64RB'', ''91RB''}, when TMN is ''1.1''" << std::endl;
    }

    return true;
}

void lte_getDefaultTM() {
}
